package bairui.international.console.web.controller.branch.branch.staff;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.http.entity.ContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import com.lianjing.sh.project.commons.util.Util_FileDeal;
import com.lianjing.sh.spring.web.controller.base.action.Action;

import bairui.international.common.config.Config_Path;
import bairui.international.common.tool.Util_GenerateQRCode;
import bairui.international.model.domain.jpa.TB_BranchCompanyStaff;
import bairui.international.service.Service_BranchCompanyStaff;

/**
 *
 * 生成二维码大图
 *
 * @generated
 * 
 * @see STest_C_BranchCompanyStaff_Generate_FileDownload 测试
 *
 */
@Controller
public class C_BranchCompanyStaff_Generate_FileDownload
 extends SC_BranchCompanyStaff_Generate_FileDownload 
{
	@Autowired private Service_BranchCompanyStaff service_BranchCompanyStaff;
	@Autowired private Config_Path config_Path;
	
	/**
	 * 下载文件
	 */
	@Action(FileDownload.class)
	@GetMapping(FileDownload.RequestMappingValue)
	public void fileDownload(
		HttpServletRequest request,
		HttpServletResponse response, 
		@PathVariable(name=FileDownload.PathVariableName.BranchId) long branchId, 
		@PathVariable(name=FileDownload.PathVariableName.Id) long id
	) throws Exception {
		TB_BranchCompanyStaff bean = service_BranchCompanyStaff.findById(id);
		/*
		 * 创建二维码
		 */
		// 重新创建二维码
		if(null == bean.getDimensionalUrl()){
			String fileName = Util_GenerateQRCode.generateQRCode(
					config_Path.getPosition_Image_QR_CompanyStaff(), 
					"companyStaff", 
					String.valueOf(bean.getId()),
					bean.getUser().getAvatarUrl()
				);
			service_BranchCompanyStaff.resetDimensionalUrl(bean, fileName);
		}
		// 下载设置
		Util_FileDeal.downloadFile(request, response, "二维码.jpg", ContentType.IMAGE_JPEG);
		// 生成大图二维码并下载
		Util_GenerateQRCode.generateBigQRCode(
				 response.getOutputStream(), 
				 "companyStaff", 
				 String.valueOf(bean.getId()),
				 bean.getUser().getAvatarUrl()
			);
	}
	

}
